home *** CD-ROM | disk | FTP | other *** search
- /* ttyfix. Copyright (c) 1990 by David M. Hayden
- * All rights Reserved.
- *
- * This program may be used and distributed at will, provided that it is
- * distributed with this notice and the above copyright notice. You may not
- * sell this program for profit without the written permission of the author.
-
- * This program is a simple filter to fix some of the problems with the
- * windows 3.0 "Generic / Text Only" printer driver. The program fixes the
- * following two bugs:
- *
- * 1: When printing justified paragraphs, the driver prints zillions
- * of one-character lines. This collapes them into one line
- * 2: The driver ends lines with a line-feed/carriage return pair
- * instead of the other way around.
- *
- */
-
- #include <stdio.h>
-
- char line[200]; /* holds input line of text */
-
- main(int argc, char **argv)
- {
- int index = 0, i;
- char ch;
- FILE *fp;
-
- /* open the input file */
- if (argc>=2) fp = freopen(argv[1], "rb", stdin);
- else fp = stdin;
-
- for (i=0; i<200; i++) line[i] = ' ';
-
- while (fread(&ch, 1, 1, fp) > 0) {
- switch(ch) {
- case '\r':
- index = 0;
- break;
- case '\n':
- line[index]=0;
- puts(line);
- for(i=0; i<200; i++) line[i] = ' ';
- index = 0;
- break;
-
- default:
- if (line[index] == ' ' || line[index] == '_') {
- line[index] = ch;
- }
- index++;
- break;
- }
- }
- }